const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')


module.exports = {
  entry:'./src/main.js',
  output:{
    filename:'index.js',
    path:path.join(__dirname,'dist'),  //必须是绝对路径
  },
  module:{
    rules:[
      {
        test:/\.less$/,
        use:[
          'style-loader',
          'css-loader',
          'less-loader'
        ]
      },
      {
        test:/\.css$/,
        use:[
          'style-loader',
          'css-loader',
        ]
      },
      {
        test:/\.vue$/,
        use:[
          'vue-loader'
        ]
      },
      {
        test:/\.js$/,
        use: {
            loader: 'babel-loader',
            options: {
                presets: ['@babel/preset-env']
            }
        },
        include: path.resolve(__dirname, 'src')
      },
      {
        test:/\.js$/,
        use: {
          loader: 'eslint-loader',
        },
        enforce:'pre',
        include: path.resolve(__dirname, 'src')
      },
      {
        test:/\.(jpe?g|png|gif)$/i,
        use:{
          loader:'url-loader',
          options:{
            limit:10240,
            // callback:{
            //   loader:'file-loader'
            // }
          }
        }
      },
      {
        test:/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        use:{
          loader:'url-loader',
          options:{
            limit:10240,
          }
        }
      },
      {
        test:/\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
        use:{
          loader:'url-loader',
          options:{
            limit:10240,
          }
        }
      },
    ]
  },
  plugins:[
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title:'vue项目打包',
      mate:{
        viewport: 'width=device-width'
      },
      template:'./public/index.html'
    }),
  ]
}